#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n; char x;
    cin >> n >> x;
    int ans = 0;
    for (int i=1; i<=n; ++i)
    {
        string a = to_string(i);
        for (unsigned int j=0; j<a.size(); ++j)
        {
            if (a[j] == x) ++ans;
        }
    }
    cout << ans;
    return 0;
}
